import Vue from 'vue';
import Router from 'vue-router';
import HomePage from '../views/homePage.vue'; // 首页
import Cake from '../views/cake.vue'; // 生日蛋糕页
import Foot from '../views/foot.vue'; // 食玩所页
import ShoppingBag from '../views/shoppingBag.vue'; // 购物袋
import My from '../views/my.vue'; // 个人页
import Detail from '../views/detail.vue' // 详情页
import Login from '../views/login.vue' // 登录页
import mPhone from "../components/mPhone.vue"
import User from "../components/user.vue"

Vue.use(Router);

const routes = [
    { path: '/', name: 'HomePage', component: HomePage, meta: { title: "诺心蛋糕官网-生日蛋糕_水果蛋糕_慕斯_芝士蛋糕-LE CAKE蛋糕店诺心蛋糕网上订购", showTab: true } },
    { path: '/cake', name: 'Cake', component: Cake, meta: { title: "诺心蛋糕官网-生日蛋糕_水果蛋糕_慕斯_芝士蛋糕-LE CAKE蛋糕店诺心蛋糕网上订购", showTab: true } },
    { path: '/foot', name: 'Foot', component: Foot, meta: { title: "诺心蛋糕官网-生日蛋糕_水果蛋糕_慕斯_芝士蛋糕-LE CAKE蛋糕店诺心蛋糕网上订购", showTab: true } },
    { path: '/shoppingBag', name: 'ShoppingBag', component: ShoppingBag, meta: { title: "诺心蛋糕官网-生日蛋糕_水果蛋糕_慕斯_芝士蛋糕-LE CAKE蛋糕店诺心蛋糕网上订购", showTab: true } },
    { path: '/my', name: 'My', component: My, meta: { title: "诺心蛋糕官网-生日蛋糕_水果蛋糕_慕斯_芝士蛋糕-LE CAKE蛋糕店诺心蛋糕网上订购", showTab: true } },
    { path: '/detail/:id', name: 'Detail', component: Detail }, // 路由传参: :id是通过路由链接传递给detail页面的参数
    {
        path: '/login',
        name: 'Login',
        component: Login,
        meta: { title: "诺心蛋糕官网-生日蛋糕_水果蛋糕_慕斯_芝士蛋糕-LE CAKE蛋糕店诺心蛋糕网上订购" },
        redirect: "/login/mPhone",
        children: [{
            path: "mPhone",
            name: "mPhone",
            component: mPhone,
            meta: { title: "诺心蛋糕官网-生日蛋糕_水果蛋糕_慕斯_芝士蛋糕-LE CAKE蛋糕店诺心蛋糕网上订购" }
        }, {
            path: "user",
            name: "User",
            component: User,
            meta: { title: "诺心蛋糕官网-生日蛋糕_水果蛋糕_慕斯_芝士蛋糕-LE CAKE蛋糕店诺心蛋糕网上订购" }
        }]
    }
]

const router = new Router({
    routes
})

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title;
    }
    next();
})

export default router;